﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace LaunchMeNot {
    /// <summary>
    /// Counts down to zero.
    /// </summary>
    public class CountdownTimer : Control {
        public static readonly DependencyProperty IsArmedProperty = DependencyProperty.Register("IsArmed", typeof(bool), typeof(CountdownTimer));
        /// <summary>
        /// Determines whether the timer is armed (meaning notification should be given when time remaining is zero).
        /// </summary>
        /// <value><c>true</c> if this timer is armed, otherwise <c>false</c>.</value>
        public bool IsArmed {
            get { return (bool)GetValue(IsArmedProperty); }
            set { SetValue(IsArmedProperty, value); }
        }

        public static readonly DependencyProperty TimeRemainingProperty = DependencyProperty.Register("TimeRemaining", typeof(TimeSpan), typeof(CountdownTimer));
        /// <summary>
        /// Gets or sets the time remaining.
        /// </summary>
        /// <value>The time remaining.</value>
        public TimeSpan TimeRemaining {
            get { return (TimeSpan)GetValue(TimeRemainingProperty); }
            set { SetValue(TimeRemainingProperty, value); }
        }

        /// <summary>
        /// Determines whether the time has any time left.
        /// </summary>
        /// <value><c>true</c> if the time remaning is zero, otherwise <c>false</c>.</value>
        public bool IsDone {
            get { return TimeRemaining.TotalMilliseconds == 0; }
        }

        /// <summary>
        /// Initializes a new, unarmed <see cref="CountdownTimer"/>.
        /// </summary>
        public CountdownTimer() {
            TimeRemaining = new TimeSpan(0);
            IsArmed = false;
        }

        /// <summary>
        /// Initializes a new, unarmed <see cref="CountdownTimer"/>.
        /// </summary>
        /// <param name="remaining">The time from which to count down.</param>
        public CountdownTimer(TimeSpan remaining) {
            TimeRemaining = remaining;
            IsArmed = false;
        }
    }
}
